#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int a[N], pos[N];
int l[505], r[505], f[505], c[505];
void init() {
  int k = sqrt(n);
  rep(i, 1, n) pos[i] = (i - 1) / k + 1;
  int cnt = pos[n];
  rep(i, 1, cnt) {
    l[i] = (i - 1) * k + 1;
    r[i] = i * k;
  }
  r[cnt] = n;
}
void pushdown(int id) {
  if (f[id]) {
    rep(i, l[id], r[id]) a[i] ^= 1;
    f[id] = 0;
  }
}
void update_inb(int L, int R) {
  int id = pos[L];
  pushdown(id);
  rep(i, L, R) a[i] ^= 1;
  c[id] = 0;
  rep(i, l[id], r[id]) if (a[i]) c[id]++;
}
void update(int L, int R) {
  int id1 = pos[L], id2 = pos[R];
  if (id1 == id2) {
    update_inb(L, R);
    return;
  }
  update_inb(L, r[id1]), update_inb(l[id2], R);
  rep(i, id1 + 1, id2 - 1) f[i] ^= 1, c[i] = r[i] + 1 - l[i] - c[i];
}
int query_inb(int L, int R) {
  int id = pos[L];
  pushdown(id);
  int res = 0;
  rep(i, L, R) if (a[i]) res++;
  return res;
}
int query(int L, int R) {
  int id1 = pos[L], id2 = pos[R];
  if (id1 == id2) return query_inb(L, R);
  int res = query_inb(L, r[id1]) + query_inb(l[id2], R);
  rep(i, id1 + 1, id2 - 1) res += c[i];
  return res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  init();
  while (m--) {
    int op, L, R;
    cin >> op >> L >> R;
    if (op == 0)
      update(L, R);
    else
      cout << query(L, R) << endl;
  }
  return 0;
}